<%@ page language="java" pageEncoding="UTF-8"%>

<script type="text/javascript">
var task = null;	//记录当前的任务JSON

function loadItem(){
	var id = request("id");
	if(id == undefined || id == ""){
		$.alert("错误的参数！");
		return;
	}
	
	block("#detailForm", "正在加载数据...");
	$.ajax({
		type: "GET",
		cache: false,
		url: "detail.json?id=" + id,
		dataType: "json",
		success: loadSucceedCallback,
		error:function(message){
			unblock("#detailForm");
			$.alert(message);
		}  
	});	
}

function loadSucceedCallback(data){
	unblock("#detailForm");
	if (!data.succeed) {
		$.notice(data.message);
		return;
	}
	task = data.data;
	fillItem(data.data);
}

function fillItem(item){
	$("#taskTitle").text(" - " + item.name);
	$("#taskId").val(item.id);
	$("#taskName").val(item.name);
	$("#taskStatus").val(getTaskStatus(item.status));
	$("#taskStatus").data("code", item.status);
	$("#taskAssignedDate").val(item.assignedDate);
	$("#taskTemplate").val(item.templateName).data("id", item.templateId);
	$("#taskPlanEndDate").val((item.planEndDate!=null)?item.planEndDate.slice(0,10):item.planEndDate);
	$("#taskStartDate").val(item.startDate);
	$("#taskEndDate").val(item.endDate);
	$("#taskLocationAddress").val(item.locationAddress);
	$("#taskLongitude").val(item.longitude);
	$("#taskLatitude").val(item.latitude);
	$("#taskLocateDate").val(item.locateDate);
	$("#taskExecPerson").val(item.execPersonName);
	$("#taskExecPerson").data("id", item.execPersonId);
	$("#taskProject").val(item.projectName);
	$("#taskProject").data("id", item.projectId);
	$("#taskContent").val(item.content);
	$("#taskDescription").val(item.description);
	$("#taskCreator").val(item.creatorName);
	$("#taskCreator").data("id", item.creatorId);
	$("#taskCreateType").val(getCreateType(item.createType));
	
	$.each(item, function(key,value){
		$("#"+key).val(value);
	});
	
	if(item.status == "completed"){
		//$("#taskStartDateCg").show();
		//$("#taskEndDateCg").show();
		
		$("#exportButton").show();
		var supervId = $("#supervId").val();
		if(supervId == undefined || supervId == ""){
			loadSupervByTask();
			$("#supervPanel").data("loaded",false);
			
			
			//$("#exportButton").hide();
		}
		$("#assignedButton").hide();
		$("#progressButton").hide();
	} else if(item.status == "in_process"){
		$("#assignedButton").show();
		$("#progressButton").hide();
		$("#exportButton").hide();
	} else if(item.status == "assigned"){
		$("#progressButton").show();
		$("#assignedButton").hide();
		$("#exportButton").hide();
	} 
	
	if(item.createType == "dispatch"){
		$("#taskPlanEndDateCg").show();
	}
}

function toProgress() {
	if (!confirm('一般是错误的使用了“设为待办”功能后才需要恢复此任务为“处理中”。\n请确认是否强制将此任务设置为“处理中”？')) {
		return;
	}
	
	block("#detailForm");
	$.ajax({
		type: "POST",
		url: "toProgress.json",
		data: {"id": task.id},
		dataType: "json",
		success: function(data){
			unblock("#detailForm");
			if(!data.succeed){
				$.alert("操作失败，原因为：\n" + data.message);
				return;
			}
			$.info("操作成功！");
			task.status = 'in_process';
			fillItem(task);
		},
		error: function(message){
			unblock("#detailForm");
			$.alert("操作失败：" + message);
		}
	});
}

function toAssigned() {
	if (!confirm('一般是终端接收任务失败后，才需要设置此任务为“待办”。\n请确认是否强制将此任务设置为“待办”？')) {
		return;
	}
	
	block("#detailForm");
	$.ajax({
		type: "POST",
		url: "toAssigned.json",
		data: {"id": task.id},
		dataType: "json",
		success: function(data){
			unblock("#detailForm");
			if(!data.succeed){
				$.alert("操作失败，原因为：\n" + data.message);
				return;
			}
			$.info("操作成功！");
			task.status = 'assigned';
			fillItem(task);
		},
		error: function(message){
			unblock("#detailForm");
			$.alert("操作失败：" + message);
		}
	});
}

function cleanAddress() {
	if (!confirm('一般是勘察地点有乱码才需要重置地址，此操作会清空地址信息然后服务器自动获取新地址，但坐标信息不会变化。\n请确认是否重置此任务的地址？')) {
		return;
	}
	
	block("#detailForm");
	$.ajax({
		type: "POST",
		url: "cleanAddress.json",
		data: {"id": task.id},
		dataType: "json",
		success: function(data){
			unblock("#detailForm");
			if(!data.succeed){
				$.alert("操作失败，原因为：\n" + data.message);
				return;
			}
			$.info("操作成功！");
			location.reload();
		},
		error: function(message){
			unblock("#detailForm");
			$.alert("操作失败：" + message);
		}
	});
}

$(document).ready(function() {
	loadItem();
	$("#detailForm").find("input,textarea").attr("readonly", "readonly");
});
</script>

<form id="detailForm" class="form-horizontal">
<input type="hidden" id="taskId" name="taskId" />
<fieldset>
	<div class="control-group">
		<label for="taskName"  class="control-label">名称：</label>
		<div class="controls">
		<input type="text" id="taskName" name="taskName" />
		</div>
	</div>
	<div class="control-group" id="taskStatusCg">
		<label for="taskStatus"  class="control-label">状态：</label>
		<div class="controls">
		<input type="text" id="taskStatus" name="taskStatus" readonly="readonly" />
		</div>
	</div>
	<div class="control-group" style="display: none;" id="taskAssignedDateCg">
		<label for="taskAssignedDate"  class="control-label">下发时间：</label>
		<div class="controls">
		<input type="text" id="taskAssignedDate" name="taskAssignedDate" readonly="readonly" />
		</div>
	</div>
	<div class="control-group">
		<label for="taskProject"  class="control-label">项目：</label>
		<div class="controls">
		<input type="text" id="taskProject" name="taskProject" readonly="readonly" />
		</div>
	</div>
	<div class="control-group">
		<label for="taskExecPerson"  class="control-label">勘察人员：</label>
		<div class="controls">
		<input type="text" id="taskExecPerson" name="taskExecPerson" readonly="readonly" />
		</div>
	</div>
	<div class="control-group">
		<label for="taskTemplate"  class="control-label">模板：</label>
		<div class="controls">
		<input type="text" id="taskTemplate" name="taskTemplate" readonly="readonly"/>
		</div>
	</div>
	<div class="control-group" style="display: none;" id="taskPlanEndDateCg">
		<label for="taskPlanEndDate"  class="control-label">要求完成日期：</label>
		<div class="controls">
		<input type="text" id="taskPlanEndDate" name="taskPlanEndDate" />
		</div>
	</div>
	<div class="control-group" id="taskLocateDateCg">
		<label for="taskLocateDate"  class="control-label">定位时间：</label>
		<div class="controls">
		<input type="text" id="taskLocateDate" name="taskLocateDate" readonly="readonly" />
		</div>
	</div>
	<div class="control-group" id="taskLocationAddressCg">
		<label for="taskLocationAddress"  class="control-label">勘察地点：</label>
		<div class="controls">
		<input type="text" id="taskLocationAddress" name="taskLocationAddress" readonly="readonly" />
		</div>
	</div>
	<div class="control-group">
		<label for="taskLongitude"  class="control-label">经度：</label>
		<div class="controls">
		<input type="text" id="taskLongitude" name="taskLongitude" readonly="readonly" />
		</div>
	</div>
	<div class="control-group">
		<label for="taskLatitude"  class="control-label">纬度：</label>
		<div class="controls">
		<input type="text" id="taskLatitude" name="taskLatitude" readonly="readonly" />
		</div>
	</div>
	<div class="control-group" style="display: none;" id="taskStartDateCg">
		<label for="taskStartDate"  class="control-label">实际开始日期：</label>
		<div class="controls">
		<input type="text" id="taskStartDate" name="taskStartDate" readonly="readonly" />
		</div>
	</div>
	<div class="control-group" style="display: none;" id="taskEndDateCg">
		<label for="taskEndDate"  class="control-label">实际结束日期：</label>
		<div class="controls">
		<input type="text" id="taskEndDate" name="taskEndDate" readonly="readonly" />
		</div>
	</div>
	<div class="control-group">
		<label for="taskContent"  class="control-label">任务描述：</label>
		<div class="controls">
		<textarea id="taskContent" name="taskContent"></textarea>
		</div>
	</div>
	<div class="control-group">
		<label for="taskDescription"  class="control-label">勘察内容：</label>
		<div class="controls">
		<textarea id="taskDescription" name="taskDescription"></textarea>
		</div>
	</div>
	
	<!-- 新增字段  start -->
	<div class="control-group">
		<label for="projectPeriods" class="control-label">工程期数：</label>
		<div class="controls">
			<input type="text" id="projectPeriods" name="projectPeriods" readonly="readonly"/>
		</div>
	</div>
	<div class="control-group">
		<label for="area" class="control-label">地州：</label>
		<div class="controls">
			<input type="text" id="area" name="area" readonly="readonly"/>
		</div>
	</div>
	<div class="control-group">
		<label for="county" class="control-label">区县：</label>
		<div class="controls">
			<input type="text" id="county" name="county" readonly="readonly"/>
		</div>
	</div>
	<div class="control-group">
		<label for="towns" class="control-label">乡镇：</label>
		<div class="controls">
			<input type="text" id="towns" name="towns" readonly="readonly"/>
		</div>
	</div>
	<div class="control-group">
		<label for="stationTypeName" class="control-label">站点类别：</label>
		<div class="controls">
			<input type="text" id="stationTypeName" name="stationTypeName" readonly="readonly"/>
		</div>
	</div>
	<div class="control-group">
		<label for="baseStationName" class="control-label">基站名称：</label>
		<div class="controls">
			<input type="text" id="baseStationName" name="baseStationName" readonly="readonly"/>
		</div>
	</div>
	<div class="control-group">
		<label for="baseStationCode" class="control-label">基站编码：</label>
		<div class="controls">
			<input type="text" id="baseStationCode" name="baseStationCode" readonly="readonly"/>
		</div>
	</div>
	<div class="control-group">
		<label for="mainSeparation" class="control-label">主选点名称：</label>
		<div class="controls">
			<input type="text" id="mainSeparation" name="mainSeparation" readonly="readonly"/>
		</div>
	</div>
	<div class="control-group">
		<label for="baseStationSite" class="control-label">基站地址：</label>
		<div class="controls">
			<input type="text" id="baseStationSite" name="baseStationSite" readonly="readonly"/>
		</div>
	</div>
	<div class="control-group">
		<label for="altitude" class="control-label">海拔高度：</label>
		<div class="controls">
			<input type="text" id="altitude" name="altitude" readonly="readonly"/>
		</div>
	</div>
	<div class="control-group">
		<label for="relativeHeight" class="control-label">相对高度：</label>
		<div class="controls">
			<input type="text" id="relativeHeight" name="relativeHeight" readonly="readonly"/>
		</div>
	</div>
	<div class="control-group">
		<label for="secondMoveDistance" class="control-label">二搬距离：</label>
		<div class="controls">
			<input type="text" id="secondMoveDistance" name="secondMoveDistance" readonly="readonly"/>
		</div>
	</div>
	<div class="control-group">
		<label for="sitePropertiesName" class="control-label">站址属性：</label>
		<div class="controls">
			<input type="text" id="sitePropertiesName" name="sitePropertiesName" readonly="readonly"/>
		</div>
	</div>
	<div class="control-group">
		<label for="propertiesName" class="control-label">配套产权归属：</label>
		<div class="controls">
			<input type="text" id="propertiesName" name="propertiesName" readonly="readonly"/>
		</div>
	</div>
	<div class="control-group">
		<label for="areaTypeName" class="control-label">区域类型：</label>
		<div class="controls">
			<input type="text" id="areaTypeName" name="areaTypeName" readonly="readonly"/>
		</div>
	</div>
	<div class="control-group">
		<label for="coveringTarget" class="control-label">覆盖目标：</label>
		<div class="controls">
			<input type="text" id="coveringTarget" name="coveringTarget" readonly="readonly"/>
		</div>
	</div>
	<div class="control-group">
		<label for="constructionModelName" class="control-label">工程建设模式：</label>
		<div class="controls">
			<input type="text" id="constructionModelName" name="constructionModelName" readonly="readonly"/>
		</div>
	</div>
	<div class="control-group">
		<label for="siteValidName" class="control-label">站点是否有效：</label>
		<div class="controls">
			<input type="text" id="siteValidName" name="siteValidName" readonly="readonly"/>
		</div>
	</div>
	<div class="control-group">
		<label for="siteValidReason" class="control-label">站点无效原因：</label>
		<div class="controls">
			<input type="text" id="siteValidReason" name="siteValidReason" readonly="readonly"/>
		</div>
	</div>
	<!-- 新增字段  end -->
	
	<div class="control-group" id="taskCreatorCg">
		<label for="taskCreator"  class="control-label">创建人：</label>
		<div class="controls">
		<input type="text" id="taskCreator" name="taskCreator" readonly="readonly" />
		</div>
	</div>
	<div class="control-group">
		<label for="taskCreateType"  class="control-label">任务类型：</label>
		<div class="controls">
		<input type="text" id="taskCreateType" name="taskCreateType" readonly="readonly" />
		</div>
	</div>
</fieldset>
</form>